
*****************
*Fixing errors in raw data from SND0204 
*errors located by Dawn Teele & an RA (Emily Katz) in 2020 and 2021. Nearly 1000 errors. 


/*Setup error check document 

use "/Users/teele/Dropbox/Book2/data_b2/Sweden/Sweden Analysis/Sweden_merged.dta", clear
replace Electmen=Elect if (Electmen==0 | Electmen==.)  & Elect!=. & year<=1920

label define urban 0 "Rural" 1 "Urban"
label values CityTown urban

keep ID year parish parish_name county district Electmen Elect Electwomen VTmen VTwomen VT CityTown

keep if CityTown==1
xtset ID year
sort ID year
bys ID: gen change=Electmen-Electmen[_n-1]

keep if inlist(year,1928,1932,1936 )
*/ 




*There are 19 obvious errors. 10 of those were where the men's and women's eligibility totals did not equal the total eligibility and were easy to fix. It was usually just a digit recorded incorrectly. 

*there was no way to know for a few: 1109090 1921 has a lot of errors, I think that Men's turnout is off by 200, and that men in the electorate was off by 600. But it seems to have been invented in 1921, so it wouldn't be in our analysis anyway. 514060 the 1944 values of the electorate are both 0. The district was losing population so I have no way to telll what the values would be. 

gen check1=Electmen-VTmen
gen check=1 if check1<0
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if check1<0

*12 instances in all the years total that men's turnout recorded as larger than men's eligibility. 

gen check2=Electwomen-VTwomen
replace check=2 if check2<0 & check==.
brow check ID district parish year Elect Electmen Electwomen VTmen VTwomen VT if check2<0
*12 for women too. 


*One anomaly with turnout, district 8 munic 11. Says valid and invalid votes are 165 but women cast 70 and men recorded at 15. I think men should be 95, changing

replace VTmen=95 if district==8 & parish==11 & VTmen==15 & year==1921

*district 11	munic 3	1932, the total electorate is 200 more than exists. Women's probably off by 200. 

replace Electwomen=280 if district==11 & parish==3 & Electwomen==80 & year==1932

*District 1 munic 47 in 1924 clearly a mistake because total electorate was 1259 and eligible men were 624 
replace Electwomen=635 if district==1 & parish==47 & Electwomen==35 & year==1924

*District 1 munic 9, the total electorate was 100 more than the sum of the values in the mens and womens' cells. Since the turnout of women was higher than the women's value, I assume the digit was entered incorrectly as 243 instead of 343. 
replace Electwomen=343 if district==1 & parish==9 & Electwomen==243 & year==1928

*district 3 munic 3 1932. Total electorate was 300 higher than that recorded. I assume women in electorate incorrectly labled "10" instead of "310" 
replace Electwomen=310 if district==3 & parish==3 & Electwomen==10 & year==1932

*district 6 munic 23, 1944. Total electorate was about 600 more than that recorded with current values. I assume women eligibility 790 instead of "191". This makes women almost even with men and turnout lower than eligibility. 
replace Electwomen=790 if district==6 & parish==23 & Electwomen==191 & year==1944

*district 7 munic 6 I think that the 4 was incorrectly coded as a 2 for both men and women. Then we are only off by one for eligibility. 
replace Electwomen=445 if district==7 & parish==6 & Electwomen==244 & year==1944

replace Electmen=440 if district==7 & parish==6 & Electmen==240 & year==1944


*dist 12 munic 1 1944. The women's eligibility is clearly too low for turnout and total eligibility. the 206 should have been 286. 
replace Electwomen=286 if district==12 & parish==1 & Electwomen==206 & year==1944


*dist 8	munic 3	in 1944. I think that both men and women eligibility neeed to have a "5" instead of "1" in frist digit that the second dight was off by 10 for the men, and the third digit wrong for women. 
replace Electwomen=570 if district==8 & parish==3 & Electwomen==173 & year==1944

replace Electmen=559 if district==8 & parish==3 & Electmen==169 & year==1944



*district 12	munic 7	in 1932. Clearly men's total wrong by 100. 

replace Electmen=353 if district==12 & parish==7 & Electmen==253 & year==1932


*Men 
*district 1 munic 1 in 1944, total electorate was 90 higher than the men and women sum, and men's turnout was higher than male electorate. I assume that digit was wrong and Elect men is 199 instead of 119 
replace Electmen=199 if district==1 & parish==1 & Electmen==119 & year==1944

*district 5 munic 10, 1944. Men's eligibility obviously too low. change from 63 to 269 to meet total eligibility. 

replace Electmen=269 if district==5 & parish==10 & Electmen==63 & year==1944

*district 11 munic 9, 1932, men's eligibility 100 too low to get to the total eligibility or to have it be more than men's turnout. 

replace Electmen=373 if district==11 & parish==9 & Electmen==273 & year==1932

***thorny ones
sort year
brow check district parish  year Elect Electmen Electwomen VTmen VTwomen VT if district==6 & parish==4 & ID==1606040

*District 6 munip 4 1940. both men and women wrong. I checked the 1936 data and if men grew by 2 and women grew by one then the total eligibility and the turnout make sense. 
replace Electwomen=230 if district==6 & parish==4 & Electwomen==142 & year==1940

replace Electmen=228 if district==6 & parish==4 & Electmen==148 & year==1940


*dist 1 munic 15, 1924, the electorate size is wrong as is men's eligibility
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==1101150

replace Electmen=656 if district==1 & parish==15 & Electmen==356 & year==1924

replace Elect=1369 if district==1 & parish==15 & Elect==1069 & year==1924

**district 8	munic 6	1940, obviously men's electorate should be the same number as year before and year after 116. subtract to get women's total. 
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==1608060


replace Electwomen=120 if district==8 & parish==6 & Electwomen==0 & year==1940

replace Electmen=116 if district==8 & parish==6 & Electmen==0 & year==1940


*district 9 munic 9 1921 TOTAL CLUSTER no way to know. 
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==1109090


*district 13	munic 31	1921. If elect men is 354 and I add 100 to the electorate, then the vote totals make sense. Plus 354 is the elecorate value for men in 1924, and it is 355 in 1928
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==1513310

replace Electmen=354 if district==13 & parish==31 & Electmen==254 & year==1921

replace Elect=725 if district==13 & parish==31 & Elect==625 & year==1921

*district 14	munic 6	1944
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==514060

*dist 9 mpio 3 year 1944* I think total electorate fell by too much given previous year, and that women's electorae is 100 off. 
sort year
brow check district parish year Elect Electmen Electwomen VTmen VTwomen VT if ID==1909030

replace Electwomen=357 if district==9 & parish==3 & Electwomen==257 & year==1944

replace Elect=719 if district==9 & parish==3 & Elect==619 & year==1944

****************************

*January 2022 Problems
***************************

*In the data where the VT_M-VT_W is too large

replace Electmen=266 if ID==1210260 & year==1921/* Groenby 1921 the elect men incorrect. */  

replace Electmen=429 if ID==1210090 & year==1932 /*Skurupkg, the women's value of the electorate was in the men's colum, driving women's turnout too high */ 

replace Electwomen=515 if ID==1210090 & year==1932 /*Skurupkg, the women's value of the electorate was in the men's colum, driving women's turnout too high */ 

replace Elect=429+515 if ID==1210090 & year==1932 


replace Elect=975 if year==1920 & ID== 1712060  /*Gunnarsk had the wrong numbers for 1920 */ 
replace Electmen=975 if year==1920 & ID== 1712060 
replace VTmen=402 if year==1920 & ID== 1712060 /*male voter turnout*/ 
replace Valid=398 if year==1920 & ID== 1712060 /*they had valid votes wrong */ 
replace CON=71 if year==1920 & ID== 1712060
replace AGR=2 if year==1920 & ID== 1712060
replace LIB=211 if year==1920 & ID== 1712060
replace SOC = 65 if year==1920 & ID== 1712060
replace COM = 11 if year==1920 & ID== 1712060
replace OTH = 38 if year==1920 & ID== 1712060



*Vika in 1917, completely incorrect coding, p.135 of 1917 electoral register
/*
	v34	v35		v36	v38	v39	v40	v41	v42	v37
	eligible	 votes cast	ineligible	total ballots	moderate	bondes	liberal	soc dem	vanster soc	invalv4
Vika	344	218	75	217	27	53	56	18	63	1 */

replace Elect=344 if ID==2001060 & year==1917
replace VTmen=218 if ID==2001060 & year==1917
		
replace Valid=217 if ID==2001060 & year==1917
replace CON=27 if ID==2001060 & year==1917
replace AGR=53 if ID==2001060 & year==1917
replace LIB=56 if ID==2001060 & year==1917
replace SOC=18 if ID==2001060 & year==1917
replace COM=63 if ID==2001060 & year==1917
replace Invalid=1 if ID==2001060 & year==1917

replace SOC=232 if ID==2110040 & year==1917 /* Parish of Los is added to Hamra in the dataset the socialst vote tally actually (113+119 = 232) */ 

*1920

replace CON= 40 if ID==1601100 & year==1920 /* Parish Hassleen put the number of total votes in the conservative vote share column*/ 

*Federation of farmers' votes were recorded, but actually allocated to convervative (Hoger) and liberalso
replace AGR=0 if ID==1216080 & year==1920


replace Valid=282 if ID==218040 & year==1920 /*vallid votes was writen as 228, actually 282*/ 

replace CON=3 if ID==1709030 & year==1920 /*Hoger actually 3, not 30) */ 


replace SOC=9 if ID== 1512210 & year==1920 /*Gullered, the social dem tally taken from the row above in the data*/ 

/*Radene the row above was accidentally entered */ 
replace CON= 24 if ID==1603250 & year==1920
replace AGR = 16 if ID==1603250 & year==1920
replace LIB = 5 if ID==1603250 & year==1920
replace SOC	 = 1 if ID==1603250 & year==1920
replace COM = 0 if ID==1603250 & year==1920  

/*
v51 	Total Votes: The right wing		       51  Antal röster: Högern	
v57 	Number of votes: The Federation of Farmers		       57  Antal röster: Jordbrukarnas Riksförbund	
v52 	Total Votes: Agrarians		       52  Antal röster: Bondeförbundet	
v53 	Total Votes: Liberala		       53  Antal röster: Liberala	
v55 	Number of votes: Social Democrats		       55  Antal röster: Socialdemokraterna	
v56 	Number of votes: Left Socialists		       56  Antal röster: Vänstersocialister	
v54 	Number of votes: Frisinnade		       54  Antal röster: Frisinnade	
CON	OTH	AGR	LIB	SOC	COM

33 --> actually 24, was recording row above	0	2--> 16	8--> 5	4-->1	2 --> 0	46	*/ 

replace SOC=0 if ID==1210060 & year==1920 /*took the value from the year above*/ 

replace AGR= 7 if ID==1210060 & year==1920

replace AGR = 0 if ID==1210060 & year==1920
replace LIB = 12 if ID==1210060 & year==1920
replace SOC = 21 if ID==1210060 & year==1920
replace COM = 0 if ID==1210060 & year==1920  /*left socialists */

replace Valid=330 if ID==1515030 & year==1921 /*Dalskog valv4 votes */ 
replace SOC=217 if ID==1515090 & year==1921 /*Meller Koping */ 
replace COM=0 if ID==1515090 & year==1921

replace Valid=679 if ID==208050 & year==1921


*Linde koping (valid votes incorrectly stated as 1313)*
replace Valid=3018 if ID==1813010 & year==1928

/* lofta lots missing with no sense. */ 
replace CON=150 if ID==801100 & year==1932
replace LIB= 0 if ID==801100 & year==1932
replace SOC=310 if ID==801100 & year==1932
replace COM=39 if ID==801100 & year==1932
replace OTH= 22 if ID==801100 & year==1932



************************
*Emily's Fixes*
************************
replace Electmen=8475 if ID==522080 & year==1932
replace Electmen=6694 if ID==1005080 & year==1932

*************************
*Emily's Fixes for Sheet1
*************************
replace Elect=275 if ID==1603130 & year==1921
replace Elect=905 if ID==604010 & year==1921
replace Elect=774 if ID==1515090 & year==1921
replace Electmen=281 if ID==1705020 & year==1921
replace Elect=1307 if ID==217110 & year==1921
replace Elect=147 if ID==1211060 & year==1921
replace Elect=149 if ID==2105030 & year==1921
replace Elect=2606 if ID==1621080 & year==1921
replace Elect=2036 if ID==1008080 & year==1921
replace Electmen=277 if ID==209030 & year==1921
replace Electwomen=279 if ID==209030 & year==1921
replace Elect=556 if ID==209030 & year==1921
replace Elect=7288 if ID==2509010 & year==1921
replace Electwomen=1369 if ID==515020 & year==1921
replace Elect=136 if ID==1603120 & year==1921
replace Elect=10025 if ID==1811010 & year==1921
replace Elect=844 if ID==202020 & year==1921
replace Electwomen=768 if ID==1206030 & year==1921
replace Electwomen=200 if ID==302020 & year==1921
replace Elect=449 if ID==1513050 & year==1921
replace Elect=683 if ID==410020 & year==1921
replace Elect=1409 if ID==802020 & year==1921
replace Elect=774 if ID==1212100 & year==1921

replace Elect=356 if ID==1410100 & year==1924
replace Electwomen=463 if ID==1410020 & year==1924
replace Elect=423 if ID==1607010 & year==1924
replace Elect=426 if ID==1105150 & year==1924
replace Elect=452 if ID==216050 & year==1924
replace Elect=456 if ID==1211160 & year==1924
replace Elect=668 if ID==1405010 & year==1924
replace Electwomen=310 if ID==202040 & year==1924
replace Elect=169 if ID==519060 & year==1924
replace Elect=376 if ID==1001040 & year==1924
replace Elect=1043 if ID==1415010 & year==1924
replace Elect=369 if ID==521050 & year==1924
replace Electwomen=173 if ID==1710070 & year==1924
replace Elect=141 if ID==520040 & year==1924
replace Elect=592 if ID==518060 & year==1924
replace Electwomen=397 if ID==1615010 & year==1924
replace Elect=202 if ID==1205160 & year==1924
replace Elect=426 if ID==1802020 & year==1924
replace Elect=3673 if ID==2001070 & year==1924

replace Elect=297 if ID==201060 & year==1928
replace Elect=645 if ID==1002070 & year==1928
replace Elect=1144 if ID==1204040 & year==1928
replace Elect=136 if ID==1610140 & year==1928
replace Electmen=233 if ID==1607120 & year==1928
replace Elect=468 if ID==1513060 & year==1928
replace Elect=501 if ID==203060 & year==1928
replace Elect=517 if ID==201010 & year==1928
replace Elect=1737 if ID==2303070 & year==1928
replace Elect=623 if ID==518030 & year==1928
replace Electmen=322 if ID==1212110 & year==1928
replace Elect=166 if ID==1609020 & year==1928
replace Elect=174 if ID==1603300 & year==1928
replace Elect=195 if ID==901720 & year==1928
replace Elect=1065 if ID==1105140 & year==1928
replace Electwomen=460 if ID==1806010 & year==1928
replace Elect=119 if ID==1604450 & year==1928
replace Elect=1316 if ID==1207160 & year==1928
replace Elect=463 if ID==1613050 & year==1928
replace Elect=883 if ID==508060 & year==1928
replace Elect=1864 if ID==524080 & year==1928

replace Elect=575 if ID==518050 & year==1932
replace Elect=934 if ID==2301040 & year==1932
replace Electwomen=518 if ID==1203230 & year==1932
replace Elect=1108 if ID==207040 & year==1932
replace Elect=113 if ID==1512030 & year==1932
replace Elect=119 if ID==1602030 & year==1932
replace Elect=948 if ID==1108040 & year==1932
replace Elect=259 if ID==506040 & year==1932
replace Electmen=352 if ID==504020 & year==1932
replace Electwomen=325 if ID==504020 & year==1932
replace Elect=2464 if ID==809040 & year==1932
replace Elect=154 if ID==204070 & year==1932
replace Elect=290 if ID==1609050 & year==1932
replace Elect=6001 if ID==1617080 & year==1932
replace Elect=653 if ID==1711050 & year==1932
replace Elect=848 if ID==502040 & year==1932
replace Elect=234 if ID==1211050 & year==1932
replace Elect=235 if ID==1211110 & year==1932
replace Elect=251 if ID==1209110 & year==1932
replace Elect=652 if ID==1601060 & year==1932
replace Elect=55 if ID==1209030 & year==1932
replace Elect=333 if ID==1001040 & year==1932
replace Elect=341 if ID==1205040 & year==1932
replace Elect=424 if ID==1202230 & year==1932
replace Elect=451 if ID==1516010 & year==1932
replace Elect=911 if ID==1205170 & year==1932
replace Electwomen=228 if ID==1608040 & year==1932
replace Elect=474 if ID==1513050 & year==1932
replace Elect=497 if ID==514030 & year==1932
replace Electwomen=862 if ID==1206030 & year==1932
replace Elect=561 if ID==901610 & year==1932
replace Elect=624 if ID==518030 & year==1932
replace Elect=1521 if ID==202290 & year==1932
replace Elect=1265 if ID==1102060 & year==1932
replace Elect=639 if ID==1516040 & year==1932
replace Elect=4390 if ID==2102030 & year==1932
replace Elect=2331 if ID==1008080 & year==1932
replace Elect=133 if ID==1508040 & year==1932
replace Elect=138 if ID==1610140 & year==1932
replace Elect=157 if ID==1201150 & year==1932
replace Electmen=455 if ID==519120 & year==1932
replace Elect=907 if ID==502030 & year==1932
replace Elect=444 if ID==607200 & year==1932
replace Elect=2377 if ID==2202110 & year==1932
replace Elect=488 if ID==217060 & year==1932
replace Elect=1093 if ID==1105140 & year==1932
replace Elect=373 if ID==1204270 & year==1932
replace Elect=212 if ID==518100 & year==1932
replace Elect=936 if ID==1207210 & year==1932

replace Electwomen=1644 if ID==1004030 & year==1936
replace Elect=308 if ID==901440 & year==1936
replace Electmen=833 if ID==1414010 & year==1936
replace Elect=3374 if ID==2107030 & year==1936
replace Elect=2563 if ID==2102040 & year==1936
replace Elect=692 if ID==2315040 & year==1936
replace Elect=1121 if ID==601160 & year==1936
replace Elect=358 if ID==609030 & year==1936
replace Elect=505 if ID==704050 & year==1936
replace Elect=2096 if ID==706110 & year==1936
replace Elect=389 if ID==1210050 & year==1936
replace Elect=282 if ID==1206250 & year==1936
replace Elect=1108 if ID==1206090 & year==1936
replace Elect=859 if ID==1212200 & year==1936
replace Electmen=586 if ID==1203310 & year==1936
replace Electwomen=735 if ID==1210250 & year==1936
replace Elect=2046 if ID==1203210 & year==1936
replace Electmen=229 if ID==1613040 & year==1936
replace Electwomen=228 if ID==1613040 & year==1936
replace Electwomen=205 if ID==1610010 & year==1936
replace Electmen=212 if ID==1610010 & year==1936
replace Elect=299 if ID==1607110 & year==1936
replace Elect=130 if ID==1602040 & year==1936
replace Elect=122 if ID==1604360 & year==1936
replace Electmen=605 if ID==1601470 & year==1936
replace Electwomen=594 if ID==1601470 & year==1936
replace Elect=163 if ID==1604030 & year==1936
replace Elect=219 if ID==1608060 & year==1936
replace Elect=1592 if ID==1601150 & year==1936
replace Elect=161 if ID==1603300 & year==1936
replace Electmen=253 if ID==1611150 & year==1936
replace Electmen=172 if ID==203020 & year==1936
replace Electwomen=165 if ID==203020 & year==1936
replace Elect=647 if ID==206010 & year==1936
replace Electmen=993 if ID==217010 & year==1936
replace Electwomen=282 if ID==402060 & year==1936
replace Electwomen=1497 if ID==1701060 & year==1936
replace Electmen=1091 if ID==2208130 & year==1936
replace Electmen=145 if ID==1509130 & year==1936
replace Electwomen=133 if ID==1509130 & year==1936
replace Elect=415 if ID==1504050 & year==1936
replace Elect=226 if ID==1508110 & year==1936
replace Elect=227 if ID==1506120 & year==1936
replace Elect=456 if ID==1512200 & year==1936
replace Electmen=813 if ID==1809010 & year==1936
replace Electwomen=745 if ID==1809010 & year==1936
replace Elect=1247 if ID==1801040 & year==1936
replace Electwomen=524 if ID==1808030 & year==1936
replace Elect=1100 if ID==1801130 & year==1936
replace Electmen=528 if ID==527080 & year==1936
replace Elect=256 if ID==520020 & year==1936
replace Elect=638 if ID==521010 & year==1936

replace Electwomen=1242 if ID==1004010 & year==1940
replace Elect=5052 if ID==1002130 & year==1940
replace Elect=90 if ID==902340 & year==1940
replace Elect=434 if ID==1406020 & year==1940
replace Elect=5005 if ID==2112080 & year==1940
replace Electmen=748 if ID==1301120 & year==1940
replace Electwomen=698 if ID==1301120 & year==1940
replace Elect=2542 if ID==1302050 & year==1940
replace Electmen=95 if ID==603070 & year==1940
replace Electwomen=103 if ID==603070 & year==1940
replace Elect=316 if ID==609240 & year==1940
replace Elect=3436 if ID==1205130 & year==1940
replace Electwomen=291 if ID==1211070 & year==1940
replace Elect=916 if ID==1207050 & year==1940
replace Elect=1400 if ID==1207030 & year==1940
replace Elect=380 if ID==1208060 & year==1940
replace Elect=424 if ID==1206170 & year==1940
replace Elect=470 if ID==1206060 & year==1940
replace Elect=171 if ID==1202110 & year==1940
replace Electmen=1094 if ID==512010 & year==1940
replace Electwomen=999 if ID==512010 & year==1940
replace Elect=2093 if ID==512010 & year==1940
replace Electmen=401 if ID==1612070 & year==1940
replace Electwomen=383 if ID==1612070 & year==1940
replace Elect=386 if ID==1608010 & year==1940
replace Elect=258 if ID==1615120 & year==1940
replace Elect=759 if ID==1604320 & year==1940
replace Elect=162 if ID==1615130 & year==1940
replace Elect=139 if ID==1603300 & year==1940
replace Electwomen=663 if ID==1604120 & year==1940
replace Electwomen=1881 if ID==218020 & year==1940
replace Electmen=1716 if ID==218020 & year==1940
replace Elect=255 if ID==217020 & year==1940
replace Elect=2089 if ID==217010 & year==1940
replace Elect=7420 if ID==227080 & year==1940
replace Elect=10807 if ID==220080 & year==1940
replace Elect=2887 if ID==1706050 & year==1940
replace Elect=767 if ID==1705030 & year==1940
replace Elect=623 if ID==1909010 & year==1940
replace Electwomen=266 if ID==1513240 & year==1940
replace Electmen=262 if ID==1508060 & year==1940
replace Elect=528 if ID==1508060 & year==1940
replace Elect=226 if ID==1507240 & year==1940
replace Elect=212 if ID==1507070 & year==1940
replace Electmen=755 if ID==1506230 & year==1940
replace Elect=166 if ID==1512070 & year==1940
replace Elect=1065 if ID==1809030 & year==1940
replace Elect=890 if ID==508060 & year==1940
replace Elect=257 if ID==512060 & year==1940
replace Elect=139 if ID==520100 & year==1940

replace Elect=3427 if ID==1004070 & year==1944
replace Elect=1322 if ID==1002020 & year==1944
replace Elect=1052 if ID==1407010 & year==1944
replace Elect=299 if ID==705150 & year==1944
replace Elect=733 if ID==702070 & year==1944
replace Elect=703 if ID==705120 & year==1944
replace Electwomen=245 if ID==1206020 & year==1944
replace Elect=819 if ID==1212040 & year==1944
replace Electwomen=50 if ID==1205150 & year==1944
replace Elect=117 if ID==1205150 & year==1944
replace Elect=319 if ID==1204130 & year==1944
replace Elect=582 if ID==1213060 & year==1944
replace Elect=306 if ID==1601400 & year==1944
replace Elect=122 if ID==1601110 & year==1944
replace Electwomen=193 if ID==1608120 & year==1944
replace Elect=233 if ID==1601530 & year==1944
replace Electmen=233 if ID==1606040 & year==1944
replace Elect=140 if ID==1602020 & year==1944
replace Elect=223 if ID==1608110 & year==1944
replace Elect=849 if ID==1601320 & year==1944
replace Elect=411 if ID==1610010 & year==1944
replace Elect=323 if ID==201060 & year==1944
replace Elect=390 if ID==301010 & year==1944
replace Elect=725 if ID==304010 & year==1944
replace Elect=913 if ID==313010 & year==1944
replace Elect=482 if ID==1708040 & year==1944
replace Electmen=198 if ID==1513200 & year==1944
replace Electwomen=200 if ID==1513200 & year==1944
replace Electmen=488 if ID==1515010 & year==1944
replace Elect=252 if ID==1512140 & year==1944
replace Electmen=89 if ID==1513170 & year==1944
replace Electmen=1500 if ID==1504060 & year==1944
replace Electmen=224 if ID==1804010 & year==1944
replace Electwomen=792 if ID==1815020 & year==1944
replace Elect=297 if ID==512030 & year==1944
replace Elect=235 if ID==519040 & year==1944
replace Electmen=186 if ID==521050 & year==1944
replace Electwomen=173 if ID==521050 & year==1944
replace Electwomen=420 if ID==513020 & year==1944
replace Electmen=429 if ID==513020 & year==1944
replace Elect=400 if ID==510050 & year==1944
replace Electwomen=642 if ID==527080 & year==1944
replace Elect=644 if ID==518060 & year==1944



**********************************************************
*Dawn's code this is run inside of SWE_data prep_1911-1944.do
**********************************************************
*errors in size of the electorate (October 2019)

egen e2=rowtotal(Electmen Electwomen)

count if e2!=Elect /*418*/ 

compare e2 Elect if e2!=Elect /*182 where the sum is less than what is reported in Elect, 234 where the sum is more than Elect */ 

gen percdiff=(abs(e2-Elect))/Elect


replace parish_name="VASTRA" if ID==1212120
/*SUNNEK is Sunne Köping in the original */ 
/*KAELVENE is Kälvene */
/*OSTERTAL is Östertälje in Stockholm 219010*/ 
/*Vaamb is Våmb 1207110*/
/*SKEGLING  is Skeglinge */ 
/*STKOPP is in Kopparbergs Lan, so I think it is stad kopparberg */ 
/*FRISSLA is Fritsla 1509020 */ 
/*BJOERKEB is Björkeberg 505050 
SOEDERK is Söderköping 
SKARALK Skara Landskomm 
RAEVE is Bäve 1412020
LANNERYR is Lane-Ryr	1412010 

SKURUPKG is Skurups köping 1210090

*/



*DT Jan 2021: the two below were replace Elect and that was wrong. The wrong number was elect men. 
replace Electmen=6694 if ID==1005080 & year==1932
replace Electmen=8475 if ID==522080 & year==1932

replace Electmen=826 if ID==1604250	& year==1928
replace Elect=	1023 if ID==2004190	& year== 1924 /*double checked jan 2021 this is correct */ 



replace Elect=244	if ID==506010 & year== 1921
replace Elect=2825 	if ID==1402060	& year==1924
replace Elect=496	if ID==1606070	& year==1921
replace Elect=5296	if ID==	1002130	& year== 1944
	
replace Elect=645	if ID==1513120	& year== 1944

replace Elect=969	if 	ID==1302060	& year== 1940
replace Elect=283 	if 	ID==506040 	& year== 1936
replace Elect=2838 	if 	ID==1418010	& year== 1932
replace Elect=998 	if 	ID==808090	& year== 1928

*************
*1921 Fixed Nov 2019
*************
replace Elect=293	if ID==1203060	& year== 1921
replace Elect=3426	if ID==1219080	& year==   1921
replace Elect=389	if ID==1208020	& year==  1921
replace Elect=242	if ID==504070	& year==  1921
replace Elect=667 	if ID==1516040 	& year==1921

replace Elect=299 if ID==1108060 & year==1921

replace Elect=e2 if ID==812040 & year==1921

replace Elect=e2 if ID==1410100 & year==1921
replace Elect=e2 if ID==1109250 & year==1921
replace Elect=e2 if ID==1710050 & year==1921
replace Elect=e2 if ID==1712070 & year==1921
replace Elect=e2 if ID==1405040 & year==1921
replace Elect=e2 if ID==1406010 & year==1921
replace Elect=e2 if ID==1201050 & year==1921
replace Elect=e2 if  year==1921 & ID==1212120
replace Elect=e2 if  year==1921 & ID==1512110

replace Elect=e2 if  year==1921 & ID==901040
replace Elect=e2 if  year==1921 & ID==1513320

replace Electmen=121	if ID==	1601370 & year==1921 /*checked original Boja*/ 
replace Electwomen=131	if ID==	1601370 & year==1921
replace Electwomen=568	if ID==	509090 & year==1921

replace Electmen=121	if ID==1210260 & year==1921 
replace Electmen=383	if ID==1406070 & year==1921 

*************
*1924 Fixed Nov 2019
*************

replace Elect=e2 if  year==1924 & ID==607210

replace Elect=e2 if  year==1924 & ID==1515020
replace Elect=e2 if  year==1924 & ID==2211070
replace Elect=e2 if  year==1924 & ID==1301050
replace Elect=e2 if  year==1924 & ID==1213070
replace Elect=e2 if  year==1924 & ID==1106140
replace Elect=e2 if  year==1924 & ID==1601300
replace Elect=e2 if  year==1924 & ID==1517050
replace Elect=e2 if  year==1924 & ID==1517050
replace Elect=e2 if  year==1924 & ID==1901100
replace Elect=e2 if  year==1924 & ID==1219010
replace Elect=e2 if  year==1924 & ID==1207110
replace Elect=e2 if  year==1924 & ID==1105270
replace Elect=e2 if  year==1924 & ID==502060
replace Elect=e2 if  year==1924 & ID==1206260
replace Elect=e2 if  year==1924 & ID==2110080
replace Elect=e2 if  year==1924 & ID==2001070


replace Electwomen=528	if  year==1924	& ID==1714090
replace Electwomen=300	if  year==1924	& ID==215020
replace Electwomen=59	if  year==1924	& ID==1604450


replace Electmen=363	if  year==1924	& ID==504030

*************
*1928 Fixed Nov 2019
*************

replace Elect=e2 if  year==1928 & ID==1402060
replace Elect=e2 if  year==1928 & ID==704070
replace Elect=e2 if  year==1928 & ID==605040
replace Elect=e2 if  year==1928 & ID==517020
replace Elect=e2 if  year==1928 & ID==521110
replace Elect=e2 if  year==1928 & ID==1206260
replace Elect=e2 if  year==1928 & ID==1212010
replace Elect=e2 if  year==1928 & ID==1106120
replace Elect=e2 if  year==1928 & ID==508050
replace Elect=e2 if  year==1928 & ID==1509020
replace Elect=e2 if  year==1928 & ID==505050
replace Elect=e2 if  year==1928 & ID==1813010

replace Elect=e2 if  year==1928 & ID==524080
replace Elect=e2 if  year==1928 & ID==1606220
replace Elect=e2 if  year==1928 & ID==1817080

replace Electwomen=245	if year== 1928 & ID==1208060	

replace Electwomen=245	if year== 1928 & ID==517040
replace Electwomen=349	if year== 1928 & ID==1406050

*************
**1932 Nov 2019
**************

replace Elect=e2 if  year==1932 & ID==520020
replace Elect=e2 if  year==1932 & ID==1101140
replace Elect=e2 if  year==1932 & ID==1213160
replace Elect=e2 if  year==1932 & ID==312030
replace Elect=e2 if  year==1932 & ID==1603100
replace Elect=e2 if  year==1932 & ID==1206260
replace Elect=e2 if  year==1932 & ID==1107110
replace Elect=e2 if  year==1932 & ID==1604220

replace Electmen=604	if year==1932 & ID== 1002120
replace Electwomen=536	if year==1932 & ID== 1002120

replace Electmen=869	if year==1932 & ID==1002110
replace Electwomen=840	if year==1932 & ID==1002110

replace Electmen=486	if year==1932 & ID==1412020
replace Electmen=461	if year==1932 & ID==1412020

replace Electmen=477	if year==1932 & ID==1204300
replace Electmen=484	if year==1932 & ID==1204300

replace Electmen=429 	if year==1932 & ID==1210090 
replace Electmen=515	if year==1932 & ID==1210090 





 *LINDEROE Linderöd ID==1107110





/*
replace Elect=	if ID==	& year==
replace Elect=	if ID==	& year==

replace Elect=	if ID==	& year==

replace Elect=	if ID==	& year==

replace Elect=	if ID==	& year==
*/ 

replace Electwomen=208		if ID==1208060	& year== 1921

replace Electwomen=90	if ID==304040	& year== 1928

replace Electwomen=237	if ID==1105100	& year==  1928
replace Electmen=179	if ID==	1418030 & year==1921
replace Electwomen=146	if ID==	1418030 & year==1921


replace Electwomen=131 if ID==1609060 & year==1921
replace Electmen=109 if ID==1609060 & year==1921

*errors in women's turnout (May 2019)

replace VTwomen=66	if ID==	1601350	& year==	1924
replace VTwomen=103	if ID==	701040	& year==	1940
replace VTwomen=301	if ID==	1002050	& year==	1924
replace VTwomen=390	if ID==	207030	& year==	1924
replace VTwomen=2089 if ID== 202050	& year== 1932

replace VTwomen=16040 if ID==523080	& year== 1936
*
replace VTwomen=166 if ID==409050	& year== 1936

replace VTwomen=26 if ID== 1602030	& year== 1944
replace VTwomen=284 if ID==1703010	& year== 1921

replace VTwomen=194 if ID==804010	& year== 1928


replace VTmen=1245 if ID==  1707020	& year==    1921 
/*obvious coding error off by one digit*/ 
replace VTmen=725 if ID==  1414020	& year==    1940/*obvious coding error off by one digit*/
replace VTmen=531 if ID==  702030	& year==    1932 /*obvious coding error off by one digit*/ 

replace VTmen=1095 if ID==1522080		& year==   1936	

replace VTmen=195 if ID==901530	& year==   1932

replace VTmen=2958 if ID==1617080	& year==1944

replace VTmen= 11960 if ID==523080	& year==1928
replace VTmen= 228 if ID==1710120	& year== 1932

replace VTmen=95 if district==8 & parish==11 & VTm==15 & year==1921 



gen SUMCHECK=VTmen+VTwomen
compare SUMCHECK VT
*169/18025,  observations where the sum of the total votes is not the same as the VT recorded. 0.9% For 137 of them the coding error was obvious. For example the sum of the raw vote totals would be one hundred more than the reported sum. For all of these we used our own calculated sum and replaced the value in the dataset (provided that the turnout numbers were less than the registration numbers. So that left 32/1805. this is 0.2 percent. 

replace VTmen=95 if ID==1108110 & year==1921 /*the 95 was incorrectly transcribed as a 15*/ 
replace VTwomen=284 if ID== 1703010 & year==1921 /* the 284 was incorrectly entered as 248 */ 
replace VTmen = 411 if ID == 1109090 & year==1921 /* complete wrong number written */ 
replace VT=929 if ID==1213110 & year==1921

*Digit errors
replace VT=SUMCHECK if ID==	221080	& year == 1928
replace VT=SUMCHECK if ID==	1304030	 & year ==	1932
replace VT=SUMCHECK if ID==	601050	 & year ==	1921
replace VT=SUMCHECK if ID==	1515030	 & year ==	1921
replace VT=SUMCHECK if ID==	706260	 & year ==	1921
replace VT=SUMCHECK if ID==	405070	 & year ==	1924
replace VT=SUMCHECK if ID==	902940	 & year ==	1924
replace VT=SUMCHECK if ID==	705060	 & year ==	1924
replace VT=SUMCHECK if ID==	408030	 & year ==	1928
replace VT=SUMCHECK if ID==	1710010	 & year ==	1936
replace VT=SUMCHECK if ID==	1901010	 & year ==	1928
replace VT=SUMCHECK if ID==	603030	 & year ==	1921
replace VT=SUMCHECK if ID==	1611110	 & year ==	1932
replace VT=SUMCHECK if ID==	1913030	 & year ==	1936
replace VT=SUMCHECK if ID==	1203040	 & year ==	1940
replace VT=SUMCHECK if ID==	1213060	 & year ==	1940
replace VT=SUMCHECK if ID==	1002020	 & year ==	1940
replace VT=SUMCHECK if ID==	1205160	 & year ==	1944
replace VT=SUMCHECK if ID==	1213120	 & year ==	1944
replace VT=SUMCHECK if ID==	1212060	 & year ==	1944
replace VT=SUMCHECK if ID==	1706050	 & year ==	1936
replace VT=SUMCHECK if ID==	605120	 & year ==	1944
replace VT=SUMCHECK if ID==	1608030	 & year ==	1944
replace VT=SUMCHECK if ID==	1203230	 & year ==	1928
replace VT=SUMCHECK if ID==	1601330	 & year ==	1944
replace VT=SUMCHECK if ID==	1505030	 & year ==	1932
replace VT=SUMCHECK if ID==	1211160	 & year ==	1936
replace VT=SUMCHECK if ID==	1705020	 & year ==	1921
replace VT=SUMCHECK if ID==	304060	 & year ==	1924
replace VT=SUMCHECK if ID==	705020	 & year ==	1928
replace VT=SUMCHECK if ID==	2202070	 & year ==	1928
replace VT=SUMCHECK if ID==	506050	 & year ==	1940
replace VT=SUMCHECK if ID==	1303130	 & year ==	1940
replace VT=SUMCHECK if ID==	1607050	 & year ==	1940
replace VT=SUMCHECK if ID==	1516040	 & year ==	1944
replace VT=SUMCHECK if ID==	601120	 & year ==	1921
replace VT=SUMCHECK if ID==	1423080	 & year ==	1921
replace VT=SUMCHECK if ID==	2213110	 & year ==	1924
replace VT=SUMCHECK if ID==	405030	 & year ==	1924
replace VT=SUMCHECK if ID==	217030	 & year ==	1928
replace VT=SUMCHECK if ID==	1413030	 & year ==	1928
replace VT=SUMCHECK if ID==	1206150	 & year ==	1928
replace VT=SUMCHECK if ID==	2208100	 & year ==	1928
replace VT=SUMCHECK if ID==	1203300	 & year ==	1932
replace VT=SUMCHECK if ID==	801110	 & year ==	1932
replace VT=SUMCHECK if ID==	1213040	 & year ==	1936
replace VT=SUMCHECK if ID==	2004030	 & year ==	1936
replace VT=SUMCHECK if ID==	404010	 & year ==	1936
replace VT=SUMCHECK if ID==	2104060	 & year ==	1936
replace VT=SUMCHECK if ID==	1601410	 & year ==	1940
replace VT=SUMCHECK if ID==	1210040	 & year ==	1940
replace VT=SUMCHECK if ID==	1416035	 & year ==	1940
replace VT=SUMCHECK if ID==	1601250	 & year ==	1940
replace VT=SUMCHECK if ID==	2101060	 & year ==	1944
replace VT=SUMCHECK if ID==	1601150	 & year ==	1944
replace VT=SUMCHECK if ID==	1410010	 & year ==	1944
replace VT=SUMCHECK if ID==	1308070	 & year ==	1921
replace VT=SUMCHECK if ID==	2202040	 & year ==	1921
replace VT=SUMCHECK if ID==	1615210	 & year ==	1921
replace VT=SUMCHECK if ID==	1002030	 & year ==	1921
replace VT=SUMCHECK if ID==	410020	 & year ==	1921
replace VT=SUMCHECK if ID==	201010	 & year ==	1924
replace VT=SUMCHECK if ID==	1213020	 & year ==	1924
replace VT=SUMCHECK if ID==	1804030	 & year ==	1924
replace VT=SUMCHECK if ID==	1615040	 & year ==	1924
replace VT=SUMCHECK if ID==	1603260	 & year ==	1924
replace VT=SUMCHECK if ID==	1202160	 & year ==	1928
replace VT=SUMCHECK if ID==	1906020	 & year ==	1928
replace VT=SUMCHECK if ID==	1105010	 & year ==	1932
replace VT=SUMCHECK if ID==	1425080	 & year ==	1932
replace VT=SUMCHECK if ID==	1612030	 & year ==	1932
replace VT=SUMCHECK if ID==	205050	 & year ==	1936
replace VT=SUMCHECK if ID==	518070	 & year ==	1936
replace VT=SUMCHECK if ID==	520060	 & year ==	1936
replace VT=SUMCHECK if ID==	603050	 & year ==	1936
replace VT=SUMCHECK if ID==	1601570	 & year ==	1940
replace VT=SUMCHECK if ID==	1417050	 & year ==	1944
replace VT=SUMCHECK if ID==	1607030	 & year ==	1944
replace VT=SUMCHECK if ID==	1515090	 & year ==	1944
replace VT=SUMCHECK if ID==	1507040	 & year ==	1921
replace VT=SUMCHECK if ID==	1601370	 & year ==	1921
replace VT=SUMCHECK if ID==	301070	 & year ==	1924
replace VT=SUMCHECK if ID==	1211170	 & year ==	1932
replace VT=SUMCHECK if ID==	217040	 & year ==	1932
replace VT=SUMCHECK if ID==	1601320	 & year ==	1932
replace VT=SUMCHECK if ID==	519070	 & year ==	1936
replace VT=SUMCHECK if ID==	512060	 & year ==	1936
replace VT=SUMCHECK if ID==	212020	 & year ==	1940
replace VT=SUMCHECK if ID==	215010	 & year ==	1940
replace VT=SUMCHECK if ID==	901630	 & year ==	1944
replace VT=SUMCHECK if ID==	517030	 & year ==	1944
replace VT=SUMCHECK if ID==	1201190	 & year ==	1944
replace VT=SUMCHECK if ID==	520030	 & year ==	1944
replace VT=SUMCHECK if ID==	2311050	 & year ==	1944
replace VT=SUMCHECK if ID==	1901010	 & year ==	1924
replace VT=SUMCHECK if ID==	1604340	 & year ==	1928
replace VT=SUMCHECK if ID==	401050	 & year ==	1936
replace VT=SUMCHECK if ID==	2304040	 & year ==	1936
replace VT=SUMCHECK if ID==	902340	 & year ==	1940
replace VT=SUMCHECK if ID==	1517070	 & year ==	1940
replace VT=SUMCHECK if ID==	1110030	 & year ==	1944
replace VT=SUMCHECK if ID==	1107120	 & year ==	1921
replace VT=SUMCHECK if ID==	517050	 & year ==	1940
replace VT=SUMCHECK if ID==	1901020	 & year ==	1932
replace VT=SUMCHECK if ID==	204050	 & year ==	1932
replace VT=SUMCHECK if ID==	813010	 & year ==	1940
replace VT=SUMCHECK if ID==	1610060	 & year ==	1940
replace VT=SUMCHECK if ID==	1606160	 & year ==	1940
replace VT=SUMCHECK if ID==	507020	 & year ==	1921
replace VT=SUMCHECK if ID==	1609010	 & year ==	1921
replace VT=SUMCHECK if ID==	1601240	 & year ==	1924
replace VT=SUMCHECK if ID==	1210210	 & year ==	1932
replace VT=SUMCHECK if ID==	609140	 & year ==	1932
replace VT=SUMCHECK if ID==	1204050	 & year ==	1936
replace VT=SUMCHECK if ID==	701070	 & year ==	1936
replace VT=SUMCHECK if ID==	1604210	 & year ==	1936
replace VT=SUMCHECK if ID==	1603110	 & year ==	1940
replace VT=SUMCHECK if ID==	223080	 & year ==	1940
replace VT=SUMCHECK if ID==	1604250	 & year ==	1940
replace VT=SUMCHECK if ID==	1204040	 & year ==	1944
replace VT=SUMCHECK if ID==	1804010	 & year ==	1944
replace VT=SUMCHECK if ID==	509040	 & year ==	1944
replace VT=SUMCHECK if ID==	503010	 & year ==	1944
replace VT=SUMCHECK if ID==	2013030	 & year ==	1944
replace VT=SUMCHECK if ID==	1615160	 & year ==	1944
replace VT=SUMCHECK if ID==	1207160	 & year ==	1921
replace VT=SUMCHECK if ID==	1213110	 & year ==	1921
replace VT=SUMCHECK if ID==	1812010	 & year ==	1932
replace VT=SUMCHECK if ID==	1422080	 & year ==	1944
replace VT=SUMCHECK if ID==	1217080	 & year ==	1924
replace VT=SUMCHECK if ID==	1701050	 & year ==	1928
replace VT=SUMCHECK if ID==	528080	 & year ==	1944
replace VT=SUMCHECK if ID==	2209010	 & year ==	1928
replace VT=SUMCHECK if ID==	1206240	 & year ==	1944

drop check1 check2 check percdiff SUMCHECK









